#!/usr/bin/python
# coding=utf8
#
# Copyright (C) 2011 XNData contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys, os
sys.path.append (os.getcwd () + '/../../')
import xndata.client
import xndata.client.comment
import unittest
import random
import datetime

class XNCommentClientTestCase (unittest.TestCase):

    def setUp (self):
        self.client = xndata.client.comment.XNCommentClient (uname="zhangchitc@gmail.com", upass="aaaaaaaa")


    def testPassLogin (self):
        client = xndata.client.comment.XNCommentClient (uname="zhangchitc@gmail.com", upass="aaaaaaaa")
        self.assertEqual (client.user_id, "242124580")
        self.assertEqual (client.user_name, "张弛")

    def testClientLogin (self):
        client = xndata.client.XNClient ("zhangchitc@gmail.com", "aaaaaaaa")
        pClient = xndata.client.comment.XNCommentClient (xnclient=client)
        self.assertEqual (pClient.user_id, "242124580")
        self.assertEqual (pClient.user_name, "张弛")


    def test_get_total_photo_comment (self):
        self.assertTrue (self.client.getTotalPhotoComment ("247780420", "4366803362") >= 8)
        self.assertTrue (self.client.getTotalPhotoComment ("242124580", "4382049543") >= 70)

    def test_get_total_photo_comment_list (self):
        self.assertTrue (self.client.getTotalPhotoCommentList ("247780420", "4366803362") >= 1)
        self.assertTrue (self.client.getTotalPhotoCommentList ("242124580", "4382049543") >= 3)

    def test_get_all_photo_comment (self):
        result = self.client.getAllPhotoComment ("247780420", "4366803362")
        self.assertEqual (result[0].author_id, "251173397")
        self.assertEqual (result[0].author_name, "陆珽")
        self.assertEqual (result[0].comment_id, "3976580514")
        self.assertEqual (result[0].body, "凌乱的是姑娘的那颗心")
        self.assertEqual (result[0].pub_time, datetime.datetime (2011, 5, 17, 22, 2, 0))
 
        result = self.client.getAllPhotoComment ("242124580", "4382049543")
        self.assertEqual (result[0].author_id, "239384288")
        self.assertEqual (result[0].author_name, "范一呈WoDP™")
        self.assertEqual (result[0].comment_id, "3993777545")
        self.assertEqual (result[0].body, "= = 你就一乡村企业家。。。。")
        self.assertEqual (result[0].pub_time, datetime.datetime (2011, 5, 21, 16, 1, 0))

    def test_get_total_album_comment (self):
        self.assertTrue (self.client.getTotalAlbumComment ("250529231", "310074359") >= 20)
        self.assertTrue (self.client.getTotalAlbumComment ("242124580", "420591415") >= 55)

    def test_get_total_album_comment_list (self):
        self.assertTrue (self.client.getTotalAlbumCommentList ("250529231", "310074359") >= 1)
        self.assertTrue (self.client.getTotalAlbumCommentList ("242124580", "420591415") >= 2)

    def test_get_all_album_comment (self):
        result = self.client.getAllAlbumComment ("250529231", "310074359")
        self.assertEqual (result[0].author_id, "249196584")
        self.assertEqual (result[0].author_name, "张晓旭")
        self.assertEqual (result[0].comment_id, "48735187")
        self.assertEqual (result[0].body, "很有当家女主播的范儿啊~传到博客上估计你就火了！")
        self.assertEqual (result[0].pub_time, datetime.datetime (2010, 3, 7, 23, 29, 0))
 
        result = self.client.getAllAlbumComment ("242124580", "420591415")
        self.assertEqual (result[0].author_id, "251840233")
        self.assertEqual (result[0].author_name, "廖钧")
        self.assertEqual (result[0].comment_id, "121300487")
        self.assertEqual (result[0].body, "擦 pp啊！")
        self.assertEqual (result[0].pub_time, datetime.datetime (2011, 1, 12, 3, 4, 0))

    def test_get_all_status_comment (self):
        result = self.client.getAllStatusComment ("242124580", "2201154618")
        self.assertEqual (result[0].author_id, "246700413")
        self.assertEqual (result[0].author_name, "刘沛")
        self.assertEqual (result[0].comment_id, "7471269744")
        self.assertEqual (result[0].body, "差别这么大！")
        self.assertEqual (result[0].pub_time, datetime.datetime (2011, 7, 12, 2, 6, 0))


    def test_get_total_note_comment (self):
        self.assertTrue (self.client.getTotalNoteComment ("247780420", "439115437") >= 61)
        self.assertTrue (self.client.getTotalNoteComment ("242124580", "719803155") >= 75)

    def test_get_total_note_comment_list (self):
        self.assertTrue (self.client.getTotalNoteCommentList ("247780420", "439115437") >= 3)
        self.assertTrue (self.client.getTotalNoteCommentList ("242124580", "719803155") >= 3)

    def test_get_all_note_comment (self):
        result = self.client.getAllNoteComment ("247780420", "439115437")
        self.assertEqual (result[0].author_id, "244602352")
        self.assertEqual (result[0].author_name, "倪卓敏")
        self.assertEqual (result[0].comment_id, "1383880903")
        self.assertEqual (result[0].body, "应你要求来抢沙发")
        self.assertEqual (result[0].pub_time, datetime.datetime (2010, 1, 3, 0, 41, 0))

        result = self.client.getAllNoteComment ("242124580", "719803155")
        self.assertEqual (result[0].author_id, "290332161")
        self.assertEqual (result[0].author_name, "盛达魁")
        self.assertEqual (result[0].comment_id, "1705678693")
        self.assertEqual (result[0].body, "各种妖怪。。。。师兄好政治哦。。。")
        self.assertEqual (result[0].pub_time, datetime.datetime (2011, 4, 3, 0, 5, 0))

suite1 = unittest.TestLoader().loadTestsFromTestCase (XNCommentClientTestCase)
allsuite = unittest.TestSuite ([suite1])

unittest.TextTestRunner(verbosity=2).run(allsuite)

